package cn.bugstack.infrastructure.dcc;

import cn.bugstack.types.annotations.DCCValue;
import org.springframework.stereotype.Service;

/**
 * @Author caoyi
 * @description:
 * @Date 2025/8/5 20:01
 */
@Service
public class DCCService {
    @DCCValue("downgradeSwitch:0")
    private String downgradeSwitch;
    @DCCValue("cutRange:100")
    private String cutRange;

    public boolean isDowngradeSwitch(){
        return "1".equals(downgradeSwitch);
    }

    public boolean isCutRange(String userId){
        int hashCode = Math.abs(userId.hashCode());

        // 获取最后两位
        int lastTwoDigits = hashCode % 100;

        if(lastTwoDigits<=Integer.parseInt(cutRange)){
            return true;
        }
        return false;
    }
}
